//
//  NetworkTools+Status.swift
//  微博Swift
//
//  Created by  justinchou on 16/2/27.
//  Copyright © 2016年  justinchou. All rights reserved.
//

import Foundation

extension NetworkTools {
    /// 加载微博数据
    ///
    /// - parameter since_id: 若指定此参数，则返回ID比since_id `大` 的微博（即比since_id时间晚的微博），默认为0
    /// - parameter max_id:   若指定此参数，则返回ID `小于或等于` max_id的微博，默认为0
    /// - parameter finished: 完成回调(字典)
    func loadStatus(since_id: Int64 = 0, max_id: Int64 = 0, finished: ([String: AnyObject]?)->()) {
        
        guard let accessToken = UserAccount.sharedUserAccount.access_token else {
            //判断是否存在令牌，如果没有直接返回
            NSNotificationCenter.defaultCenter().postNotificationName(JustinWeiBoNullAccessTokenNotification, object: nil)
            return
        }
        
        let urlString = "https://api.weibo.com/2/statuses/home_timeline.json"
        var params: [String: AnyObject] = ["access_token" : accessToken]
        
        if since_id > 0 {
            params["since_id"] = NSNumber(longLong: since_id)
        }
        
        if max_id > 0 {
            params["max_id"] = NSNumber(longLong: max_id - 1)
        }
        
        request(.GET, urlString: urlString, parameters: params, finished: finished)
        
    }
}